package oop.core.view.listeners;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import oop.core.entity.Avatar;

public class EquipmentMouseListener implements MouseListener{
	/**
	 * this class listens for a click inside of the persistant Equipment window.
	 * when there is a click, the X and Y coordinates of the click are converted to the index of the
	 * item in the equipment and checked to see if they properly fell on the item.  then, depending on
	 * the mouse click, removes the equipment.
	 * @author srhinson
	 */
	private Avatar avatar;
	
	public void setAvatar(Avatar avatar)
	{
		this.avatar = avatar;
	}
	
	@Override
	public void mousePressed(MouseEvent e) {
		int x=e.getX();
		int y=e.getY();
		int code = getCode(x, y);
		System.out.print(code);
		if(code == -1)	// Didn't press an item
			return;
		avatar.unEquipItem(code+1);
	}
	
	private int getCode(int x, int y)
	{
		if((0>y)||(45<y)){
			return -1;
		}
		int codeX=x/70;
		int checkX=x%70;
		if((checkX<25)||(codeX>4)){
			return -1;
		}
		return codeX;
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
